Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
split-string
Advanced tools
The split-string npm package is used to split strings on a specified separator while respecting nested structures such as quotes, brackets, and parentheses. It provides a way to parse complex strings with multiple levels of nested delimiters.
Basic string splitting
Splits a string into an array of substrings using the specified separator.
"a.b.c".split('.')
Splitting with escaped characters
Splits a string on a separator while allowing escaped characters to be included in the results.
splitString('a\.b.c', { separator: '.' })
Splitting with brackets
Splits a string on a separator while respecting nested brackets, keeping them as part of the split segments.
splitString('a.{b.c}.d', { brackets: true })
Customizing separators and brackets
Allows customization of separators and bracket pairs for more complex string splitting scenarios.
splitString('a.{b.c}.d', { separators: ['.', ' '], brackets: { '{': '}' } })
This package offers similar functionality to split-string, allowing strings to be split into arrays of substrings. It does not, however, provide the same level of support for nested structures or escaped characters.
Split is another package that can turn a stream of text into a stream of lines. It's more focused on Node.js streams rather than simple string splitting and doesn't handle nested delimiters.
Strsplit is a simple utility for splitting strings but lacks the advanced features of split-string, such as handling nested delimiters and escaped characters.
Split a string on a character except when the character is escaped.
Install with npm:
$ npm install --save split-string
var split = require('split-string');
split('a.b.c');
//=> ['a', 'b', 'c']
// respects escaped characters
split('a.b.c\\.d');
//=> ['a', 'b', 'c.d']
// respects double-quoted strings
split('a."b.c.d".e');
//=> ['a', 'b.c.d', 'e']
Type: String
Default: .
The separator/character to split on.
Example
split('a.b,c', {sep: ','});
//=> ['a.b', 'c']
// you can also pass the separator as string as the last argument
split('a.b,c', ',');
//=> ['a.b', 'c']
Type: Boolean
Default: undefined
Keep backslashes in the result.
Example
split('a.b\\.c');
//=> ['a', 'b.c']
split('a.b.\\c', {keepEscaping: true});
//=> ['a', 'b\.c']
Type: Boolean
Default: undefined
Keep double-quotes in the result.
Example
split('a."b.c.d".e');
//=> ['a', 'b.c.d', 'e']
split('a."b.c.d".e', {keepDoubleQuotes: true});
//=> ['a', 'b.c.d', 'e']
Type: Boolean
Default: undefined
Keep single-quotes in the result.
Example
split('a.\'b.c.d\'.e');
//=> ['a', 'b.c.d', 'e']
split('a.\'b.c.d\'.e', {keepSingleQuotes: true});
//=> ['a', 'b.c.d', 'e']
Type: Boolean
Default: undefined
When true
or undefined
, throws an error on unclosed double and single quotes.
Set to false
to ignore errors and continue parsing.
Example
split('a.\'b.c', {strict: false});
//=> ['a', 'b', 'c']
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Commits | Contributor |
---|---|
7 | jonschlinkert |
1 | doowb |
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
$ npm install -g verbose/verb#dev verb-generate-readme && verb
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
$ npm install && npm test
Jon Schlinkert
Copyright © 2017, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.4.3, on April 11, 2017.
[1.0.1] - 2017-04-11
FAQs
Easy way to split a string on a given character unless it's quoted or escaped.
The npm package split-string receives a total of 6,410,583 weekly downloads. As such, split-string popularity was classified as popular.
We found that split-string demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.